//
//  RacVC.m
//  Demo
//
//  Created by lx on 2019/1/5.
//  Copyright © 2019 mgz. All rights reserved.
//

#import "RacVC.h"
#import <ReactiveCocoa/ReactiveCocoa.h>
#import <ReactiveCocoa/RACEXTScope.h>
#import <Masonry.h>
#import <MGZTools.h>
#import "UITextField+RACTools.h"
@interface RacVC ()
@property (weak, nonatomic) IBOutlet UITextField *nameTextField;
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;
@property (weak, nonatomic) IBOutlet UILabel *resultLab;

@end

@implementation RacVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view from its nib.
    [MGZLogOutputWindow printLog:@"欢迎来到RacDemo"];
    [self textOne];
    
   // [self textTwo];
}


- (void)textOne{
    [[self.nameTextField rac_textMaxLength:10] subscribeNext:^(NSString *x) {
        NSLog(@"%@",x);
    }];
    [self.passwordTextField textMaxLength:8];
    RAC(self.resultLab,text) = [[RACSignal combineLatest:@[[self.nameTextField.rac_textSignal ignore:nil],[self.passwordTextField.rac_textSignal ignore:nil]]] map:^id(RACTuple *value) {
        NSString *name = value.first;
        NSString *pw = value.second;
        name = name.length > 0 ? name :@"0";
        pw = pw.length > 0 ? pw : @"0";
        return [NSString stringWithFormat:@"%ld",name.integerValue + pw.integerValue];
    }];
}

- (void)textTwo{
    
    MGZAlertView *alert = [MGZAlertView MGZAlertNormalDefaultMessage:@"取消" alertControllerWithTitle:@"提示" message:@"123123123" preferredStyle:UIAlertControllerStyleAlert];
    [alert show];
    
//    RAC(self.resultLab,alpha) = [[[[RACObserve(self.nameTextField.text,length) distinctUntilChanged] map:^id(NSNumber *value) {
//        return value.integerValue > 0 ? @(1) : @(0);
//    }]
//        animateWithDuration:0.35 curve:RCLAnimationCurveLinear]
//           startWith:@0];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
